package 简单工厂;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;


public class OrderPizza {
//	public OrderPizza() {
//		Pizza pizza = null;
//		String orderType; // 订购的披萨类型
//		
//		pizza = new CheesePizza();
//		pizza.setName("希腊披萨");
//		
//		// 输出制作过程
//		pizza.prepare();
//		pizza.bake();
//	}
	
	public OrderPizza(SimpleFactory simpleFactory) {
		setFactory(simpleFactory);
	}
	
	SimpleFactory simpleFactory;
	Pizza pizza = null;
	public void setFactory(SimpleFactory simpleFactory) {
		String orderType = "";
		this.simpleFactory = simpleFactory;
		
		do {
			orderType = getType();
			pizza = this.simpleFactory.createPizza(orderType);
			
			if(pizza != null) {
				pizza.prepare();
				pizza.bake();
			} else {
				System.out.println("订购失败");
				break;
			}
			
		} while(true);
		
	}
	
	private String getType() {
		try {
			BufferedReader strin = new BufferedReader(new InputStreamReader(System.in));
			System.out.println("input pizza 种类：");
			String str = strin.readLine();
			return str;
			
		} catch (IOException e) {
			// TODO: handle exception
			e.printStackTrace();
			return "";
		}
	}

}
